package com.kellyfeng.spittr;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

import com.kellyfeng.spittr.domain.Spitter;

@Aspect
public class SpittrAop {
	@Pointcut("execution(* com.kellyfeng.spittr.repository.SpitterRepository.findByUsername(..))")
	public void pointToSpitter(){}
	
	/**
	 * @param jp
	 * @return 
	 * @throws Throwable
	 * AOP示例
	 */
	@Around("pointToSpitter()")
	public Object testPointToSpitter(ProceedingJoinPoint jp) throws Throwable {

		System.out.println("测试切点pointToSpitter开始");
		Object[] args = jp.getArgs();
		if (args != null) {
			System.out.println("参数为:" + args[0]);
		}
		Object rvt = jp.proceed(args);
		if (rvt != null && rvt instanceof Spitter) {
			System.out.println("返回值为:" + rvt.toString());
		}
		System.out.println("测试切点pointToSpitter结束");
		return rvt;
	}
}
